//
//  ViewController.m
//  久违没有学会的归档
//
//  Created by mac on 16/9/17.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "ViewController.h"
#import "person.h"
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
   //创建
   NSString *str=@"393931555";
   //创建归档
    NSData *data=[NSKeyedArchiver archivedDataWithRootObject:str];
    //解归档
    NSString *jiedang=[NSKeyedUnarchiver unarchiveObjectWithData:data];
    
    //遵守协议
    person *per=[[person alloc]init];
    per.name=@"国防教育纪念日";
    per.age=100;
    
    //路径
    NSString *path=NSTemporaryDirectory();
    
    NSString *strpath=[path stringByAppendingPathComponent:@"ljy.db"];
   BOOL iscall=[NSKeyedArchiver archiveRootObject:per toFile:strpath];
    if (iscall)
    {
        [self showWithname:@"归档成功"];
        NSLog(@"我不是一个神经病");
        
    }else{
        [self showWithname:@"归档失败"];
    
    }
}
-(void)showWithname:(NSString *)pa
{

    UIAlertView *al=[[UIAlertView alloc]initWithTitle:pa message:@"message" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确认", nil];
    [al show];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
